//app.js
const ald = require('./utils/ald-stat.js')

App({
  globalData: {
    navHeight: null,
    navTop: null,
    windowHeight: null,
    sessionid: '',
    avatarUrl: '',
    nickName: '',
    roleName: '',
    userType: '',
    userId: '',
    ip: 'https://www.guangguangai.com/api',
    imgIp: 'https://cos.guangguangai.com',
    appid: 'wx4196eb138596f79e',
    showLoginDialog: false,
    rewardNumber: 2, // 打卡成功的光币（默认2为不可能）
    // showSuccessDialog: false,
    invitaterId: '',
  },

  setInfo: function (res1) {
    var vm = this
    wx.getSystemInfo({
      //获取设备信息
      success: function (d) {
        console.log('获取设备信息')
        console.log(d)
        //判断用户手机是IOS还是Android
        if (d.platform == 'android') {
          wx.getShareInfo({
            //获取群详细信息
            shareTicket: res1.shareTickets,
            success: function (res) {
              //这里写你分享到群之后要做的事情，比如增加次数什么的
              //查询群的信息
              console.log('getShareInfo()>>android>>')
              console.log(res.encryptedData)
              console.log(res.iv)
              wx.showModal({
                title: '提示',
                content: '分享群成功',
                success: function (res) {
                  if (res.confirm) {
                    console.log('用户点击确定')
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                },
              })
            },
            fail: function (res) {
              //这个方法就是分享到的是好友，给一个提示
              wx.showModal({
                title: '提示',
                content: '分享好友成功',
                success: function (res) {
                  if (res.confirm) {
                    console.log('用户点击确定')
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                },
              })
            },
          })
        }
        if (d.platform == 'ios') {
          //如果用户的设备是IOS
          if (res.shareTickets != undefined) {
            console.log('分享的是群')
            wx.getShareInfo({
              shareTicket: res.shareTickets,
              success: function (res) {
                //分享到群之后你要做的事情
              },
            })
          } else {
            //分享到个人要做的事情，我给的是一个提示
            console.log('分享的是个人')
            wx.showModal({
              title: '提示',
              content: '分享好友成功',
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              },
            })
          }
        }
      },
    })
  },

  onLaunch() {
    let menuButtonObject = wx.getMenuButtonBoundingClientRect()
    wx.getSystemInfo({
      success: (res) => {
        let statusBarHeight = res.statusBarHeight,
          navTop = menuButtonObject.top, //胶囊按钮与顶部的距离
          navHeight =
            statusBarHeight +
            menuButtonObject.height +
            (menuButtonObject.top - statusBarHeight) * 2 //导航高度
        this.globalData.navHeight = navHeight
        this.globalData.navTop = navTop
        this.globalData.windowHeight = res.windowHeight
      },
      fail(err) {
        console.log(err)
      },
    })
  },
})
